// 引入路由组件
// import Home from '@/views/Home/Home.vue'
// import Login from '@/views/Login/Login.vue'
// import Register from '@/views/Register/Register.vue'
// import Search from '@/views/Search/Search.vue'
// import Detail from '@/views/Detail/Detail.vue'
// import AddCartSuccess from '@/views/AddCartSuccess/AddCartSuccess.vue'
// import ShopCart from '@/views/ShopCart/ShopCart.vue'
// import Trade from '@/views/Trade/Trade.vue'
// import Pay from '@/views/Pay/Pay.vue'
// import PaySuccess from '@/views/PaySuccess/PaySuccess.vue'
// import Center from '@/views/Center/Center.vue'

// 引入二级路由组件
// import MyOrder from '@/views/Center/MyOrder/MyOrder.vue'
// import GroupOrder from '@/views/Center/GroupOrder/GroupOrder.vue'

// 路由的配置信息
export default [
  // 重定向，在项目跑起来的时候，访问/，立马让他重定向到首页
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    component: () => import('@/views/Home/Home.vue'),
    meta: { show: true },
  },
  {
    path: '/detail/:skuId',
    component: () => import('@/views/Detail/Detail.vue'),
    meta: { show: true },
  },
  {
    path: '/login',
    component: () => import('@/views/Login/Login.vue'),
    meta: { show: false },
  },
  {
    path: '/register',
    component: () => import('@/views/Register/Register.vue'),
    meta: { show: false },
  },
  {
    path: '/search/:keyword?',
    // path: '/search',
    component: () => import('@/views/Search/Search.vue'),
    meta: { show: true },
    name: 'search',
    // 函数写法
    props: (route) => ({
      keyword: route.params.keyword,
      big: route.query.big,
    }),
  },
  {
    path: '/addcartsuccess',
    component: () => import('@/views/AddCartSuccess/AddCartSuccess.vue'),
    name: 'addcartsuccess',
    meta: { show: true },
  },
  {
    path: '/shopcart',
    component: () => import('@/views/ShopCart/ShopCart.vue'),
    name: 'shopcart',
    meta: { show: true },
  },
  {
    path: '/trade',
    component: () => import('@/views/Trade/Trade.vue'),
    name: 'trade',
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 去交易页面，必须是从购物车而来
      if (from.path == '/shopcart') {
        next()
      } else {
        // 其他的路由组件而来，停留在当前
        next('/home')
      }
    },
  },
  {
    path: '/pay',
    component: () => import('@/views/Pay/Pay.vue'),
    name: 'pay',
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      // 去支付页面，必须是从购物车而来
      if (from.path == '/trade') {
        next()
      } else {
        // 其他的路由组件而来，停留在当前
        next('/home')
      }
    },
  },
  {
    path: '/paysuccess',
    component: () => import('@/views/PaySuccess/PaySuccess.vue'),
    name: 'paysuccess',
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      // 去支付页面，必须是从购物车而来
      if (from.path == '/pay') {
        next()
      } else {
        // 其他的路由组件而来，停留在当前
        next('/home')
      }
    },
  },
  {
    path: '/center',
    component: () => import('@/views/Center/Center.vue'),
    name: 'center',
    meta: { show: true },
    // 二级路由组件
    children: [
      {
        path: '/center',
        redirect: '/center/myorder',
      },
      {
        path: 'myorder',
        component: () => import('@/views/Center/MyOrder/MyOrder.vue'),
        name: 'myorder',
      },
      {
        path: 'grouporder',
        component: () => import('@/views/Center/GroupOrder/GroupOrder.vue'),
        name: 'grouporder',
      },
    ],
  },
]
